package happy.diandiankong.api.db;

import happy.diandiankong.api.model.Pictures;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.customizers.Mapper;
import org.skife.jdbi.v2.sqlobject.mixins.Transactional;

import java.util.Date;

/**
 * Title.
 * <p>
 * Description.
 *
 * @author Bill Lv {@literal <billcc.lv@hotmail.com>}
 * @version 1.0
 * @since 2016-10-29
 */
public interface PictureDao extends AutoCloseable, Transactional<PictureDao> {
    @SqlUpdate("INSERT INTO API_PICTURES (ID, NAME, WIDTH, HEIGHT, URI, STORE_NAME, TS) VALUES (:ID, :NAME, :WIDTH, :HEIGHT, :URI, :STORE_NAME, :TS)")
    void insert(
            @Bind("ID") Long id,
            @Bind("NAME") String name, @Bind("WIDTH") Integer width, @Bind("HEIGHT") Integer height,
            @Bind("URI") String uri, @Bind("STORE_NAME") String storeName, @Bind("TS") Date ts
    );

    @SqlQuery("SELECT ID, NAME, WIDTH, HEIGHT, URI, STORE_NAME, TS FROM API_PICTURES WHERE ID = :ID")
    @Mapper(PictureMapper.class)
    Pictures findById(@Bind("ID") Long id);
}
